faApp.controller('SimuBuyHisListCtrl',['$scope','simuBuyHisService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyHisService,simuService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope});  
  $scope.jjbm = $routeParams.jjbm;
  if (!$scope.jjbm){
    $location.path("/simu/list");
    return;
  }

  $scope.list = [];
  $scope.loading = true;
  $scope.jj = [];
  
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
  });

	$scope.$watch('config',function(){
    simuBuyHisService.list($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1,
    "jjbm" : $routeParams.jjbm || "",
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	}; 
  
  $scope.remove = function(id){
    simuBuyHisService.remove(id).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $route.reload();
      }
    });
  };
}]);

faApp.controller('SimuBuyHisAddCtrl',['$scope','simuBuyHisService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyHisService,simuService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 
  $scope.jjbm = $routeParams.jjbm;
  if (!$scope.jjbm){
    $location.path("/simu/list");
    return;
  }

  $scope.item = {};
  $scope.loading = true;
  $scope.jj = [];
  
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
    $scope.item.jjbm = $scope.jj.jjbm;
    $scope.item.jjmc = $scope.jj.jjmc;
  }); 
  
  $scope.save = function(){
    if (!$scope.form.$invalid){
      simuBuyHisService.add($scope.item).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          $location.path("/simu/buyhis/list").search({jjbm:$scope.item.jjbm});
        }
      });
      
    }else{
      alert("请先完整填写表单");
    }
  };

}]);

faApp.controller('SimuBuyHisEditCtrl',['$scope','simuBuyHisService','$location','$controller','$route','$routeParams',function($scope,simuBuyHisService,$location,$controller,$route,$routeParams) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.id = $routeParams.id;
  $scope.loading = true;

  simuBuyHisService.query($scope.id).then(function(json){
    $scope.item = json.detail;
    $scope.loading = false;
  });
  
  $scope.save = function(){
    if (!$scope.form.$invalid){
      simuBuyHisService.edit($scope.item).then(function(json){
        if (json.statusCode){
          alert("出错了:" + json.statusCode);
        }else{
          $location.path("/simu/buyhis/list").search({jjbm:$scope.item.jjbm});
        }
      });
      
    }else{
      alert("请先完整填写表单");
    }
  };

}]);

faApp.controller('SimuBuyHisViewCtrl',['$scope','simuBuyHisService','$location','$controller','$route',function($scope,simuBuyHisService,$location,$controller,$route) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = [];
  $scope.loading = true;

	$scope.$watch('config',function(){
    simuBuyHisService.adList($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	}; 
}]);

faApp.controller('SimuBuyHisNewCtrl',['$scope','simuBuyHisService','simuService','$location','$controller','$route','$routeParams',function($scope,simuBuyHisService,simuService,$location,$controller,$route,$routeParams) {   
  $controller('BaseCtrl', {$scope: $scope});
  $scope.jjbm = $routeParams.jjbm;
  if (!$scope.jjbm){
    $location.path("/simu/list");
    return;
  }
  $scope.list = [];
  $scope.loading = true;
  $scope.jj = [];
  $scope.createBy='';
  simuService.query({jjbm:$scope.jjbm}).then(function(json){
    $scope.jj = json.detail;
    $scope.createBy=$scope.jj.createBy;
  });

  $scope.$watch('config',function(){
    simuBuyHisService.list($scope.config).then(function(json){
      $scope.list = json.list;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

  $scope.config = {
    "pageSize" : 20,
    "pageNo" : 1,
    "jjbm" : $routeParams.jjbm || "",
  };
  
  $scope.pageChanged = function(){
    $scope.config.pageNo = $scope.pager.pageNo;
  }; 
  
  $scope.remove = function(id){
    simuBuyHisService.remove(id).then(function(json){
      if (json.statusCode){
        alert("出错了:" + json.statusCode);
      }else{
        $route.reload();
      }
    });
  };
  $scope.edit = function(v){
    $scope.itemIndex = v;
    $scope.item={
      "id":$scope.list[v]['id'],
      "jjmc":$scope.list[v]['jjmc'],
      "gpdm":$scope.list[v]['gpdm'],
      "gpjc":$scope.list[v]['gpjc'],
      "cgs":$scope.list[v]['cgs'],
      "zltgbl":$scope.list[v]['zltgbl'],
      "cgbd":$scope.list[v]['cgbd'],
      "bdgs":$scope.list[v]['bdgs'],
      "bdbl":$scope.list[v]['bdbl'],
      "jzrq":$scope.list[v]['jzrq'],
    };
  };
  
  $scope.save = function(){
    $scope.item.jjbm = $scope.jj.jjbm;
    $scope.item.jjmc = $scope.jj.jjmc;
    if (!$scope.form.$invalid){
      if($scope.item.id==undefined){
        //新增操作
       simuBuyHisService.add($scope.item).then(function(json){
              if (json.statusCode){
                alert("出错了:" + json.statusCode);
              }else{
                $route.reload();
              }
        });
      }else{
        //编辑操作
        simuBuyHisService.edit($scope.item).then(function(json){
          if (json.statusCode){
            alert("出错了:" + json.statusCode);
          }else{
            $route.reload();
          }
        });
      }
    }else{
      alert("请先完整填写表单");
    }

  };
  

}]);




